package com.le.tester.leetcode;

import java.util.*;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * createTime：2022/11/21 16:40
 * description：
 */
public class ErrorNums {

    public int[] findErrorNums(int[] nums) {

        //List<Integer> collect = Arrays.stream(nums).boxed().collect(Collectors.toList());
        //使用map获取重复的元素
        //int count = 0;
        Map<Integer, Integer> map = new HashMap<>();
        List<Integer> resultList = new ArrayList<>(Arrays.asList(0, 0));
        //存在bug，测试用例{2，10，7，10，7}
//        for (int num : nums) {
//            if (map.containsKey(num)) {
//                map.put(num, ++count);
//            } else {
//                count = 0;
//                map.put(num, ++count);
//            }
//        }

        for (int num : nums) {
            Integer oldCount = map.get(num);
            if (Objects.isNull(oldCount)) {
                map.put(num, 1);
            } else {
                map.put(num, oldCount + 1);
            }
        }

        for (Integer key : map.keySet()) {
            if (!resultList.contains(0)) {
                break;
            }
            if (map.get(key) > 1) {
                resultList.set(0, key);
                if (!map.containsKey(1)) {
                    resultList.set(1, 1);
                    break;
                }
            }
            if (!map.containsKey(key + 1) && resultList.contains(0)) {
                resultList.set(1, key + 1);
            }

        }
        return resultList.stream().mapToInt(Integer::valueOf).toArray();
    }

    public static void main(String[] args) {
        int[] ints = {1, 3, 3};
        System.out.println(Arrays.toString(new ErrorNums().findErrorNums(ints)));
    }
}
